package org.example.weboj.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")  // 允许对所有接口的跨域请求
                .allowedOrigins("http://localhost:4200",
//                        "http://121.199.167.209:4200",
                        "http://121.199.167.209",
                        "https://121.199.167.209")  // 允许前端地址
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")  // 允许的 HTTP 方法
                .allowedHeaders("*")
                .allowCredentials(true);
    }
}
